home *** CD-ROM | disk | FTP | other *** search
/ PC Media 2 / PC MEDIA CD02.iso / share / udos / fgrep103 / matchfou.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-28  |  1.3 KB  |  38 lines

  1. #include <stdio.h>
  2. #include "bm.h"
  3. #include "extern.h"
  4. #include "proto.h" /* N2 04-05-91 */
  5.  
  6. void MatchFound(struct PattDesc *Desc,int BuffPos,char *Buffer,char *BuffEnd)
  7.  {
  8.         char *MLineBegin, *MLineEnd;
  9.         Desc->Success = 0;
  10.         if (cFlag)
  11.          {
  12.           ++MatchCount;
  13.           return;
  14.          } /* if */
  15.         /* Start points to first character after a successful match */
  16.         MLineBegin = MLineEnd = Desc->Start - 1;
  17.         while(MLineBegin >=Buffer && *MLineBegin != '\n')
  18.          {
  19.           --MLineBegin;
  20.          }
  21.         ++MLineBegin;
  22.         while( MLineEnd <= BuffEnd && *MLineEnd != '\n') ++MLineEnd;
  23.         if (MLineEnd > BuffEnd) --MLineEnd;
  24.         /* check if exact match */
  25.         if (xFlag && !( Desc->PatLen == (*MLineEnd != '\n' ? ((MLineEnd -
  26.         MLineBegin) + 1) : (MLineEnd - MLineBegin))))
  27.          {
  28.           /* fixed 25jun85 pdbain. suppress multiple matches of the same
  29.              pattern on one line */
  30.           Desc->Start = MLineEnd + 1;
  31.           return;
  32.          }
  33.         PrintLine(BuffPos+(Desc->Start-Buffer),MLineBegin,MLineEnd,Desc->PatLen);
  34.         /* fixed 25jun85 pdbain. suppress multiple matches of the same
  35.            pattern on one line */
  36.         Desc->Start = MLineEnd + 1;
  37.  } /* MatchFound */
  38.